//管理员登录
const manager=(data)=>{
    return (dispatch)=>{
        fetch('https://yali.geekwhite.cn:3000/manager',{
          method:'POST',
          mode:'cors',
          body:JSON.stringify(data) 
        })
        .then(function(res){console.log(res);return res.text()})
        .then(res=>{
            dispatch({
                type:'MANAGER',
                managers:res
            })
        });
    }
}
//修改管理员信息
const changeManager=(data)=>{
    return (dispatch)=>{
        console.log(data)
        fetch('https://yali.geekwhite.cn:3000/changeManager',{
          method:'POST',
          mode:'cors',
          body:JSON.stringify(data) 
        })
        .then(function(res){console.log(res);return res.text()})
        .then(res=>{
            dispatch({
                type:'CHANGE',
                managers:res
            })
        });
    }
}
// 查看教室课程
const lookRoom=(data)=>{
    return (dispatch)=>{
        // console.log(data)
        fetch('https://yali.geekwhite.cn:3000/week',{
          method:'POST',
          mode:'cors',
          body:JSON.stringify(data)
        })
        .then(function(res){return res.text()})
        .then(res=>{
            // console.log(JSON.parse(res))
            dispatch({
                type:'LOOK',
                room:JSON.parse(res)
            })
        });
    }
}


// 查看活动
const lookAct=(data)=>{
    return (dispatch)=>{
        // console.log(data)
        fetch('https://yali.geekwhite.cn:3000/detail',{
          method:'POST',
          mode:'cors',
          body:JSON.stringify(data)
        })
        .then(function(res){return res.text()})
        .then(res=>{
            console.log(res)
            dispatch({
                type:'LOOKACT',
                act:JSON.parse(res)
            })
        });
    }
}

export {manager,changeManager,lookRoom,lookAct}
const student = (props) => {
    return (dispatch)=>{
         let url='https://yali.geekwhite.cn:3000/sinfor'
         let stu=JSON.stringify({type:student})
        fetch(url,{
            method:'post',
            body:stu,
            mode:'cors'
           })
        .then(res=>res.json())
        .then(res=>{
            dispatch({
                type:'STU',
                students:res,
            })
            console.log(res)
        
        })
    }
}
export {student}

const func = (oper) => {
    let url=''
    
    oper=JSON.stringify(oper)
    if(oper.slice(9,11)==='ok'||oper.slice(9,11)==='no'||oper.slice(9,11)==='de'){
        url='https://yali.geekwhite.cn:3000/aftercheck'
    }
    else{
        url='https://yali.geekwhite.cn:3000/sinfor'
    }
    console.log(url)
    console.log(oper)
    return (dispatch)=>{
        fetch(url,{
            method:'post',
            body:oper,
            mode:'cors'
        })
        .then(res=>res.text())
        .then(res=>{
            dispatch({
                type:'RET',
                rets:res,
            }) 
        }) 
    }
}
export {func}

const check = (props) => {
    let che=JSON.stringify({type:student})
    return (dispatch)=>{
         let url='https://yali.geekwhite.cn:3000/aftercheck'
        fetch(url,{
            method:'post',
            body:che,
            mode:'cors'
        })
        .then(res=>res.json())
        .then(res=>{
            dispatch({
                type:'CHE',
                checks:res[1],
            })
            
        // 
        })
    }
}
export {check}

const checked = (props) => {
    let che=JSON.stringify({type:student})
    return (dispatch)=>{
         let url='https://yali.geekwhite.cn:3000/aftercheck'
        fetch(url,{
            method:'post',
            body:che,
            mode:'cors'


        })
        .then(res=>res.json())
        .then(res=>{
            dispatch({
                type:'CHEED',
                checkeds:res[0],

            })     
        })
    }
}
export {checked}
const checkno = (props) => {
    let che=JSON.stringify({type:student})
    return (dispatch)=>{
         let url='https://yali.geekwhite.cn:3000/aftercheck'
        fetch(url,{
            method:'post',
            body:che,
            mode:'cors'
        })
        .then(res=>res.json())
        .then(res=>{
            dispatch({
                type:'CHENO',
                checknos:res[2],

            })  
            console.log(res)   
        })
    }
}
export {checkno}
// 未修好
const fix = (data) => {
    return (dispatch)=>{
        let url='https://yali.geekwhite.cn:3000/fix0'
        console.log(data)
        fetch(url,{
            method:'post',
            body:JSON.stringify(data),
            mode:'cors'
           
        })
        .then(res=>res.json())
        .then(res=>{
            dispatch({
                type:'FIX',
                fixs:res,

            })  
            console.log(res)   
        })
    }
}
export {fix}
// 已修好
const fixed = (props) => {
    return (dispatch)=>{
        let url='https://yali.geekwhite.cn:3000/fixed'
        fetch(url,{
            method:'post',
            body:'',
            mode:'cors'
           
        })
        .then(res=>res.json())
        .then(res=>{
            dispatch({
                type:'FIX',
                fixs:res,

            })  
            console.log(res)   
        })
    }
}
export {fixed}

